<template>
  <!-- 项目经理带班生产记录 -->
  <base-breadcrumb>
    <div class="page-body">
      <a-form-model
        ref="form"
        :model="formInfo"
        :rules="rules"
        :hide-required-mark="true"
      >
        <a-card :bordered="false">
          <title-name title="基本信息" />
          <a-row :gutter="24">
            <a-col
              :md="16"
              :sm="16"
            >
              <a-form-model-item
                label="所属单位"
                :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
                prop="projectId"
              >
                <org-tree-select
                  v-model="formInfo.projectId"
                  :disabled="isDisabled"
                  is-auto-select-first
                  is-need-auth
                  check-strictly
                  @select="handleProjectChanged"
                />
<!--                <BaseInput-->
<!--                  v-else-->
<!--                  v-model="formInfo.viewName"-->
<!--                  :disabled="isDisabled"-->
<!--                />-->
              </a-form-model-item>
            </a-col>
            <!--            <a-col-->
            <!--              :md="8"-->
            <!--              :sm="8"-->
            <!--            >-->
            <!--              <a-form-model-item-->
            <!--                label="所属分公司"-->
            <!--                :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"-->
            <!--                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"-->
            <!--                prop="branchComId"-->
            <!--              >-->
            <!--                <SelectSubCompany-->
            <!--                  v-if="!isDisabled"-->
            <!--                  v-model="formInfo.branchComId"-->
            <!--                  :disabled="isDisabled"-->
            <!--                />-->
            <!--                <BaseInput-->
            <!--                  v-else-->
            <!--                  v-model="formInfo.branchComName"-->
            <!--                  :disabled="isDisabled"-->
            <!--                />-->
            <!--              </a-form-model-item>-->
            <!--            </a-col>-->
            <!--            <a-col-->
            <!--              :md="8"-->
            <!--              :sm="8"-->
            <!--            >-->
            <!--              <a-form-model-item-->
            <!--                label="所属项目"-->
            <!--                :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"-->
            <!--                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"-->
            <!--                prop="projectId"-->
            <!--              >-->
            <!--                <SelectProject-->
            <!--                  v-if="!isDisabled"-->
            <!--                  v-model="formInfo.projectId"-->
            <!--                  key-value="branchComId"-->
            <!--                  :form="formInfo"-->
            <!--                  :clear-list="true"-->
            <!--                  :disabled="isDisabled"-->
            <!--                  @change="handleProjectChanged"-->
            <!--                />-->
            <!--                <BaseInput-->
            <!--                  v-else-->
            <!--                  v-model="formInfo.projectName"-->
            <!--                  :disabled="isDisabled"-->
            <!--                />-->
            <!--              </a-form-model-item>-->
            <!--            </a-col>-->

            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="带班日期"
                :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
                prop="leadDate"
              >
                <!-- <BaseInput   :value="formInfo.leadDate" /> -->
                <a-select
                  v-model="formInfo.leadDate"
                  :disabled="isDisabled"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="(item, i) in leadDateList"
                    :key="i"
                    :value="item"
                  >
                    {{
                      item
                    }}
                  </a-select-option>
                  <!-- <a-select-option :value="0">不可用</a-select-option> -->
                </a-select>
              </a-form-model-item>
            </a-col>

            <a-col
              :md="16"
              :sm="16"
            >
              <a-form-model-item
                label="形象进度"
                :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
                :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
                prop="imageProcessTypeId"
              >
                <a-col
                  :md="24"
                  :xs="24"
                >
                  <!-- <BaseInput disabled v-model="formInfo.imageProcessTypeVO.name" /> -->
                  <a-radio-group
                    v-model="formInfo.imageProcessTypeId"
                    :disabled="isDisabled"
                    style="width: 100%;"
                  >
                    <a-radio
                      v-for="item in processList"
                      :key="item.id"
                      :value="item.id"
                    >
                      {{
                        item.name
                      }}
                    </a-radio>
                  </a-radio-group>
                </a-col>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-card>
        <a-card :bordered="false">
          <title-name title="项目管理人员到岗履职情况" />
          <template v-if="!isDisabled">
            <div
              style="padding: 0 15px;"
              class="under-line"
            >
              <div class="one-line">
                <span>项目部应到岗位</span>
                <a-input
                  v-model="managerDutyPerfObj.shouldNum"
                  :max-length="20"
                  style="width: 120px;"
                />
                <span>人，实到岗位</span>
                <a-input
                  v-model="managerDutyPerfObj.realNum"
                  :max-length="20"
                  style="width: 120px"
                />
                <span>人；</span>
              </div>
              <div class="under-line">
                <div class="title">
                  未到岗人员及原因：
                </div>
                <a-textarea
                  v-model="managerDutyPerfObj.content"
                  style="text-indent: 120px;"
                  :max-length="500"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
            </div>
          </template>
          <template v-else>
            <div style="padding: 0 15px;">
              <p style="white-space: pre-line;line-height: 32px;">
                {{ formInfo.managerDutyPerf }}
              </p>
            </div>
          </template>
        </a-card>
        <a-card :bordered="false">
          <title-name title="分包管理人员到岗履职情况" />
          <!-- subManagerDutyPerf -->
          <template v-if="!isDisabled">
            <div
              style="padding: 0 15px;"
              class="under-line"
            >
              <div class="one-line">
                <span>劳务分包</span>
                <a-input
                  v-model="subManagerDutyPerfObj.labour"
                  :max-length="20"
                  style="width: 120px;"
                />
                <span>家，专业分包</span>
                <a-input
                  v-model="subManagerDutyPerfObj.major"
                  :max-length="20"
                  style="width: 120px"
                />
                <span>家；</span>
              </div>
              <div class="under-line">
                <div class="title">
                  <span>（1）今日分包单位负责人到岗</span>
                  <a-input
                    v-model="subManagerDutyPerfObj.director"
                    :max-length="20"
                    style="width: 120px"
                  />
                  <span>人，未到岗分包单位负责人及原因：</span>
                </div>
                <a-textarea
                  v-model="subManagerDutyPerfObj.directorContent"
                  style="text-indent: 530px;"
                  :max-length="300"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
              <div class="under-line">
                <div class="title">
                  <span>（2）今日分包单位安全员到岗</span>
                  <a-input
                    v-model="subManagerDutyPerfObj.safetyOfficer"
                    :max-length="20"
                    style="width: 120px"
                  />
                  <span>人，未到岗分包单位安全员及原因：</span>
                </div>
                <a-textarea
                  v-model="subManagerDutyPerfObj.safetyOfficerContent"
                  style="text-indent: 530px;"
                  :max-length="400"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
            </div>
          </template>
          <template v-else>
            <div style="padding: 0 15px;">
              <p style="white-space: pre-line;line-height: 32px;">
                {{ formInfo.subManagerDutyPerf }}
              </p>
            </div>
          </template>
        </a-card>
        <a-card :bordered="false">
          <title-name title="重点部位、关键环节的控制情况" />
          <!-- keyPartOfControl -->
          <template v-if="!isDisabled">
            <div
              style="padding: 0 15px;"
              class="under-line"
            >
              <div
                class="one-line"
                style="align-items: center;"
              >
                <span>危大工程及以上（或涉及一、二级风险）/主要施工活动管理情况：</span>
                <a-button
                  :disabled="keyPartOfControlObj.list.length >= 5"
                  type="primary"
                  size="small"
                  @click="keyPartOfControlListAdd"
                >
                  添加
                </a-button>
              </div>
              <div
                v-for="(item, index) in keyPartOfControlObj.list"
                :key="index+'_item'"
                class="under-line"
              >
                <div class="title">
                  <a-button
                    v-if="index!==0"
                    style="border-radius: 50%;"
                    type="primary"
                    size="small"
                    shape="circle"
                    icon="close"
                    @click="keyPartOfControlListDel(index)"
                  />
                  <span>（{{ index +1 }}）</span>
                  <a-input
                    v-model="item.input1"
                    :max-length="100"
                    style="width: 300px"
                  />
                  <span>部位</span>
                  <a-input
                    v-model="item.input2"
                    :max-length="100"
                    style="width: 300px"
                  />
                  <span>正在进行，安全管控情况：</span>
                </div>
                <a-textarea
                  v-model="item.input3"
                  :style="{textIndent: index==0 ? '830px' : '850px'}"
                  :max-length="300"
                  :rows="2"
                  auto-size
                />
                <div
                  class="title"
                  style="left: auto; right: -10px; bottom: 0;"
                >
                  <span>；责任人：</span>
                  <a-input
                    v-model="item.input4"
                    :max-length="100"
                    style="width: 200px"
                  />
                </div>
              　　
              </div>
              <div class="under-line">
                <div class="title">
                  <span>其它：</span>
                </div>
                <a-textarea
                  v-model="keyPartOfControlObj.other"
                  style="text-indent: 40px;"
                  :max-length="500"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
            </div>
          </template>
          <template v-else>
            <div style="padding: 0 15px;">
              <p style="white-space: pre-line;line-height: 32px;">
                {{ formInfo.keyPartOfControl }}
              </p>
            </div>
          </template>
        </a-card>
        <a-card :bordered="false">
          <title-name title="其它安全生产情况" />
          <template v-if="!isDisabled">
            <!-- others -->
            <div style="padding: 0 15px;">
              <div
                class="one-line"
                style="align-items: center;"
              >
                <span class="blodfont">1.安全检查：</span>
                <a-checkbox-group
                  v-model="otherObj.item1.check"
                  :options="['周安全检查', '节假日检查', '其它检查']"
                />
              </div>
              <div class="under-line">
                <div class="title">
                  <span>检查部位：</span>
                </div>
                <a-textarea
                  v-model="otherObj.item1.input"
                  style="text-indent: 70px;"
                  :max-length="300"
                  :rows="1"
                  auto-size
                />
              　　
              </div>
              <div
                class="one-line"
                style="align-items: center;"
              >
                <span class="blodfont">2.管理人员安全教育：</span>
                <a-checkbox-group
                  v-model="otherObj.item2.check"
                  :options="['入场教育', '月度教育', '三级班子讲安全、党员讲安全']"
                />
              </div>
              <div class="under-line">
                <div class="title">
                  <span>主要培训内容：</span>
                </div>
                <a-textarea
                  v-model="otherObj.item2.input"
                  style="text-indent: 98px;"
                  :max-length="300"
                  :rows="1"
                  auto-size
                />
              　　
              </div>
              <div class="under-line">
                <div class="title">
                  <span class="blodfont">3.安全验收（超危大工程或涉及一级风险）：</span>
                  <span>对</span>
                  <a-input
                    v-model="otherObj.item3.input1"
                    :max-length="100"
                    style="width: 300px"
                  />
                  <span>部位</span>
                  <a-input
                    v-model="otherObj.item3.input2"
                    :max-length="100"
                    style="width: 300px"
                  />
                  <span>进行验收，参与验收人员：</span>
                </div>
                <a-textarea
                  v-model="otherObj.item3.input3"
                  style="text-indent: 1090px;"
                  :max-length="300"
                  :rows="2"
                  auto-size
                />
                <div
                  class="title"
                  style="left: auto; right: -10px; bottom: 4px;padding-left: 5px;"
                >
                  <span>验收结论：</span>
                  <a-radio-group
                    v-model="otherObj.item3.input4"
                    :options="['合格', '不合格']"
                  />
                </div>
              　　
              </div>
              <div
                class="one-line"
                style="align-items: center;"
              >
                <span class="blodfont">4.安全会议：</span>
                <a-checkbox-group
                  v-model="otherObj.item4.check"
                  :options="['周(月)例会', '安全专题会', '其它会议']"
                />
              </div>
              <div class="under-line">
                <div class="title">
                  <span>会议主要内容：</span>
                </div>
                <a-textarea
                  v-model="otherObj.item4.input"
                  style="text-indent: 98px;"
                  :max-length="300"
                  :rows="1"
                  auto-size
                />
              　　
              </div>
              <div class="under-line">
                <div class="title">
                  <span class="blodfont">5.上级检查：</span>
                  <span>上级检查单位(部门)：</span>
                  <a-input
                    v-model="otherObj.item5.input1"
                    :max-length="100"
                    style="width: 300px"
                  />
                  <span>，主要隐患</span>
                </div>
                <a-textarea
                  v-model="otherObj.item5.input2"
                  style="text-indent: 585px;"
                  :max-length="300"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
              <div class="under-line">
                <div class="title">
                  <span class="blodfont">6.其它：</span>
                </div>
                <a-textarea
                  v-model="otherObj.item6.input"
                  style="text-indent: 50px;"
                  :max-length="300"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
            </div>
          </template>
          <template v-else>
            <div style="padding: 0 15px;">
              <p style="white-space: pre-line;line-height: 32px;">
                {{ formInfo.others }}
              </p>
            </div>
          </template>
        </a-card>
        <a-card :bordered="false">
          <title-name>
            安全生产隐患整改情况
            <a-button
              v-if="!isDisabled"
              :disabled="hiddenDangerObj.list.length >= 5"
              type="primary"
              size="small"
              @click="hiddenDangerObjListAdd"
            >
              添加
            </a-button>
          </title-name>
          <template v-if="!isDisabled">
            <!-- hiddenDanger -->
            <div style="padding: 0 15px;">
              <div
                v-for="(item, index) in hiddenDangerObj.list"
                :key="index+'_hd'"
              >
                <div class="under-line">
                  <div class="title">
                    <a-button
                      v-if="index!==0"
                      style="border-radius: 50%;"
                      type="primary"
                      size="small"
                      shape="circle"
                      icon="close"
                      @click="hiddenDangerObjListDel(index)"
                    />
                    <span>（{{ index+1 }}）</span>
                  </div>
                  <a-textarea
                    v-model="item.input1"
                    :style="{textIndent: index==0 ? '30px' : '60px'}"
                    :max-length="300"
                    :rows="1"
                    auto-size
                  />
                  <div
                    class="title"
                    style="left: auto; right: -10px; bottom: 0;padding-left: 5px;"
                  >
                    <a-radio-group
                      v-model="item.input2"
                      :options="['是', '否']"
                    />
                    <span>整改完成</span>
                  </div>
          　　
                </div>
                <div class="under-line">
                  <div class="title">
                    <span>整改措施及责任人：</span>
                  </div>
                  <a-textarea
                    v-model="item.input3"
                    style="text-indent: 126px;"
                    :max-length="300"
                    :rows="1"
                    auto-size
                  />
                　　
                </div>
              </div>
              <div class="under-line">
                <div class="title">
                  <span>其它：</span>
                </div>
                <a-textarea
                  v-model="hiddenDangerObj.other"
                  style="text-indent: 40px;"
                  :max-length="500"
                  :rows="2"
                  auto-size
                />
              　　
              </div>
            </div>
          </template>
          <template v-else>
            <div style="padding: 0 15px;">
              <p style="white-space: pre-line;line-height: 32px;">
                {{ formInfo.hiddenDanger }}
              </p>
            </div>
          </template>
        </a-card>
      <!-- <a-card :bordered="false" v-if="isDisabled">
          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-model-item
                label="项目管理人员到岗履职情况"
                :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
                :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
                prop="managerDutyPerf"
              >
                <a-col :span="24">
                  <BaseTextarea
                    v-model="formInfo.managerDutyPerf"
                    style="resize: none"
                    placeholder="请输入"
                    :rows="3"
                    :max-length="500"
                    :disabled="isDisabled"
                  />
                </a-col>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                label="分包管理人员到岗履职情况"
                :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
                :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
                prop="subManagerDutyPerf"
              >
                <a-col :span="24">
                  <BaseTextarea
                    v-model="formInfo.subManagerDutyPerf"
                    style="resize: none"
                    placeholder="请输入"
                    :rows="3"
                    :max-length="500"
                    :disabled="isDisabled"
                  />
                </a-col>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                label="重点部位、关键环节的控制情况"
                :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
                :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
                prop="keyPartOfControl"
              >
                <a-col :span="24">
                  <BaseTextarea
                    v-model="formInfo.keyPartOfControl"
                    style="resize: none"
                    placeholder="请输入"
                    :autosize="{ minRows: 2, maxRows: 6 }"
                    :max-length="1000"
                    :disabled="isDisabled"
                  />
                </a-col>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                label="其它安全生产情况"
                :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
                :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
                prop="others"
              >
                <a-col :span="24">
                  <BaseTextarea
                    v-model="formInfo.others"
                    style="resize: none"
                    placeholder="请输入"
                    :autosize="{ minRows: 2, maxRows: 6 }"
                    :max-length="500"
                    :disabled="isDisabled"
                  />
                </a-col>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                label="安全生产隐患整改情况"
                :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
                :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
                prop="hiddenDanger"
              >
                <a-col :span="24">
                  <BaseTextarea
                    v-model="formInfo.hiddenDanger"
                    style="resize: none"
                    placeholder="请输入"
                    :rows="5"
                    :max-length="1000"
                    :disabled="isDisabled"
                  />
                </a-col>
              </a-form-model-item>
            </a-col>
          </a-row>
      </a-card> -->
      </a-form-model>
      <div
        v-if="pageType !== 'look'"
        class="tool-btns page-btn-right-top"
      >
        <a-button
          v-if="formInfo.status === 'DRAFT'"
          type="primary"
          :loading="loading.SUBMITTED"
          @click="handleSave('SUBMITTED')"
        >
          提交
        </a-button>
        <a-button
          type="primary"
          @click="handleClose"
        >
          关闭
        </a-button>
      </div>
      <div
        v-else
        class="tool-btns page-btn-right-top"
      >
        <BasePrintButton
          type="primary"
          :before-print-fn="getPMDetailPrintReq"
        />
        <a-button
          type="primary"
          class="ml20"
          @click="handleClose"
        >
          关闭
        </a-button>
      </div>
    </div>
  </base-breadcrumb>
</template>

<script>
import { getProjectsDel } from '@/api/project/projects'
import SelectSubCompany from '@/components/Select/SelectSubCompany.vue'
import SelectProject from '@/components/Select/SelectProject.vue'
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮
import {
    getPMDetail,
    getPMDetailPrint,
    addPMProductionRecord,
    deleteProductionRecord,
    getLeaderDates,
    getTypeLabel,
} from '@/api/safetySupervision/safetySystem.js'
import { getSelectListByType } from '@/api/safetySupervision/common.js'
export default {
    name:'a'+Date.now(),
    components: {
        SelectSubCompany,
        SelectProject,
        BasePrintButton,
    },
    data() {
        return {
            implSituationList: [], // 落实情况 type:7
            prodManageList: [], // 现场生产、管理情况 type:5
            processList: [], // 形象进度 type:6
            projectInfo: {}, // 工程项目相关信息
            loading: {
                DELETE: false,
                DRAFT: false,
                SUBMITTED: false,
            },
            formInfo: {
                status: 'DRAFT',
                branchComId: '',
                projectId: '',
                fileList: [],
                imageProcessTypeId: '',
                majorRiskProject: '',
                nextWorkReq: '',
                prodManageTypeId: '',
                securityCheckId: '',
                securityCheckSysId: '',
                imageProcessTypeVO: {},
            },
            leadDateList: [],
            rules: {
                branchComId: [{ required: true, message: '请选择所属分公司', trigger: 'change' }],
                projectId: [{ required: true, message: '请选择所属项目', trigger: 'change' }],
                imageProcessTypeId: [{ required: true, message: '请选择形象进度', trigger: 'change' }],
                leadDate: [{ required: true, message: '请选择日期', trigger: 'change' }],
                managerDutyPerf: [{ required: true, message: '请输入', trigger: 'change' }],
                subManagerDutyPerf: [{ required: true, message: '请输入', trigger: 'change' }],
                keyPartOfControl: [{ required: true, message: '请选择', trigger: 'change' }],
                hiddenDanger: [{ required: true, message: '请选择', trigger: 'change' }],
                others: [{ required: true, message: '请选择', trigger: 'change' }],
            },
            managerDutyPerfObj: {
              shouldNum: '',
              realNum: '',
              content: '',
            },
            subManagerDutyPerfObj: {
              labour: '',
              major: '',
              director: '',
              directorContent: '',
              safetyOfficer: '',
              safetyOfficerContent: '',
            },
            keyPartOfControlObj: {
              list: [
                {
                  input1: '',
                  input2: '',
                  input3: '',
                  input4: '',
                }
              ],
              other: '',
            },
            otherObj: {
              item1: { check: [], input: '' },
              item2: { check: [], input: '' },
              item3: { input1: '', input2: '', input3: '', input4: '' },
              item4: { check: [], input: '' },
              item5: { input1: '', input2: '' },
              item6: { input: '' },
            },
            hiddenDangerObj: {
              list: [
                {
                  input1: '',
                  input2: '',
                  input3: '',
                }
              ],
              other: ''
            }
        }
    },
    computed: {
        pageType() {
            return this.$route.query.pageType || 'look'
        },
        isDisabled() {
            return this.pageType === 'look'
        },
        managerDutyPerf() {
          let obj = this.managerDutyPerfObj
          return `项目部应到岗位${obj.shouldNum}人，实到岗位${obj.realNum}人；\n未到岗人员及原因：${obj.content}`
        },
        subManagerDutyPerf() {
          let obj = this.subManagerDutyPerfObj
          return `劳务分包${obj.labour}家，专业分包${obj.major}家；\n`+
          `（1）今日分包单位负责人到岗${obj.director}人，未到岗分包单位负责人及原因：${obj.directorContent}\n`+
          `（2）今日分包单位安全员到岗${obj.safetyOfficer}人，未到岗分包单位安全员及原因：${obj.safetyOfficerContent}`
        },
        keyPartOfControl() {
          let obj = this.keyPartOfControlObj
          let str = '危大工程及以上（或涉及一、二级风险）/主要施工活动管理情况：\n'
          obj.list.forEach((item, index) => {
            str += `（${(index + 1)}）${item.input1}部位${item.input2}正在进行，安全管控情况：${item.input3}；责任人：${item.input4}\n`
          })
          str += `其他：${obj.other}`
          return str
        },
        others() {
          let obj = this.otherObj
          return `1.安全检查：${obj.item1.check.join('，')}\n检查部位：${obj.item1.input}\n`+
          `2.管理人员安全教育：${obj.item2.check.join('，')}\n主要培训内容：${obj.item2.input}\n`+
          `3.安全验收（超危大工程或涉及一级风险）：对${obj.item3.input1}部位${obj.item3.input2}进行验收，参与验收人员：${obj.item3.input3}；验收结论：${obj.item3.input4}\n`+
          `4.安全会议：${obj.item4.check.join('，')}\n会议主要内容：${obj.item4.input}\n`+
          `5.上级检查：上级检查单位(部门)：${obj.item5.input1}，主要隐患${obj.item5.input2}\n`+
          `6.其它：${obj.item6.input}`
        },
        hiddenDanger() {
          let obj = this.hiddenDangerObj
          let str = ''
          obj.list.forEach((item, index) => {
            str += `（${(index + 1)}）${item.input1} ${item.input2} 整改完成\n整改措施及责任人：${item.input3}\n`
          })
          str += `其他：${obj.other}`
          return str
        }
    },
    created() {
        this.getDetail()
        // this.getAllSelectList()
        //
        this.getTypeLabel()
    },
    methods: {
        keyPartOfControlListAdd() {
          this.keyPartOfControlObj.list.push({
            input1: '',
            input2: '',
            input3: '',
            input4: '',
          })
        },
        keyPartOfControlListDel(index) {
          this.keyPartOfControlObj.list.splice(index, 1)
        },
        hiddenDangerObjListAdd () {
          this.hiddenDangerObj.list.push({
            input1: '',
            input2: '',
            input3: '',
          })
        },
        hiddenDangerObjListDel(index) {
          this.hiddenDangerObj.list.splice(index, 1)
        },
        async getTypeLabel() {
            const [err, res] = await getTypeLabel()
            if (!err) {
                this.processList = res.data.IMAGE_PROCESS_TYPE
            }
        },
        async getleadDateList(params) {
            const [err, res] = await getLeaderDates(params)
            if (!err) {
                console.log(res.data)
                this.leadDateList = res.data
            }
        },
        getPMDetailPrintReq() {
            const { id } = this.$route.query
            if (!id) return
            const params = {
                id,
            }
            return getPMDetailPrint(params).then((res) => {
               let content = res[1].data.content;
               let pattern1= '管理人员安全教育：检查部位';
               content =  content.replace(pattern1, "管理人员安全教育:主要培训内容");
                return content
            })
        },
        // 获取下拉列表数据
        getAllSelectList() {
            const loopList = [
                {
                    name: 'processList',
                    type: 6,
                },
                {
                    name: 'prodManageList',
                    type: 5,
                },
                {
                    name: 'implSituationList',
                    type: 7,
                },
            ]
            loopList.forEach((item) => {
                this.getSelectList(item.type, item.name)
            })
        },
        async getSelectList(type, name) {
            const [err, res] = await getSelectListByType({ type })
            if (!err) {
                this[name] = res.data || []
            }
        },
        async handleProjectChanged(val) {
            this.formInfo.branchComId = val[val.length-2].orgId
            const id = this.formInfo.projectId
            const res = await getProjectsDel({
                projectId: id,
            }) // 获取项目详情信息
            this.projectInfo = res.data || {}

            this.getleadDateList(id)
        },
        filterEditModel(type) {
            let flag = ''
            switch (type) {
                case 'add':
                    flag = 2
                    break
                case 'edit':
                    flag = 1
                    break
                case 'look':
                    flag = 0
                    break
                default:
                    flag = 0
                    break
            }
            return flag
        },
        async getDetail() {
            const { id } = this.$route.query
            if (!id) return
            const params = {
                id,
            }
            const [err, res] = await getPMDetail(params)
            if (!err) {
                this.formInfo = {
                    ...this.formInfo,
                    ...res.data,
                }
                // console.log(res.data)
                this.formInfo.managerDutyPerf = this.formInfo.managerDutyPerf.replace(/\/n/g, "\n")
                this.formInfo.subManagerDutyPerf = this.formInfo.subManagerDutyPerf.replace(/\/n/g, "\n")
                this.formInfo.keyPartOfControl = this.formInfo.keyPartOfControl.replace(/\/n/g, "\n")
                this.formInfo.others = this.formInfo.others.replace(/\/n/g, "\n");
                let splitOthers = this.formInfo.others.split('\n');
                let pattern1= '检查部位';
                splitOthers[3] =  splitOthers[3].replace(pattern1, "主要培训内容");
                this.formInfo.others = splitOthers.join('\n');
                this.formInfo.hiddenDanger = this.formInfo.hiddenDanger.replace(/\/n/g, "\n")
                this.formInfo.imageProcessTypeId = this.formInfo.imageProcessTypeVO?.id
                this.$nextTick(async () => {
                  this.formInfo.projectId = res.data.projectId
                  await this.handleProjectChanged(this.formInfo.projectId)
                })
            }
        },
        validateForm() {
            let flag = false
            this.$refs.form.validate((valid) => {
                flag = valid
            })
            return flag
        },
        validateDetails() {
          let flag = true
          // 项目管理人员到岗履职情况校验
          let managerDutyPerfObj = this.managerDutyPerfObj;
          if (
            !managerDutyPerfObj.shouldNum &&
            !managerDutyPerfObj.realNum &&
            !managerDutyPerfObj.content
          ) {
            this.$message.error('请填写【项目管理人员到岗履职情况】')
            return false
          }
          // 分包管理人员到岗履职情况校验
          let subManagerDutyPerfObj = this.subManagerDutyPerfObj
          if (
            !subManagerDutyPerfObj.labour &&
            !subManagerDutyPerfObj.major &&
            !subManagerDutyPerfObj.director &&
            !subManagerDutyPerfObj.directorContent &&
            !subManagerDutyPerfObj.safetyOfficer &&
            !subManagerDutyPerfObj.safetyOfficerContent
          ) {
            this.$message.error('请填写【分包管理人员到岗履职情况】')
            return false
          }
          // 重点部位、关键环节的控制情况校验
          let keyPartOfControlObj = this.keyPartOfControlObj
          let notInputList = false
          keyPartOfControlObj.list.forEach((item, index) => {
            if (!item.input1 && !item.input2 && !item.input3 && !item.input4) {
              // this.$message.error(`请填写【重点部位、关键环节的控制情况】第${index + 1}项`)
              notInputList = true
            }
          })
          if (notInputList && !keyPartOfControlObj.other) {
            this.$message.error(`请填写【重点部位、关键环节的控制情况】`)
            return false
          }
          // 其它安全生产情况情况 校验
          let otherObj = this.otherObj
          if (
            otherObj.item1.check.length == 0 && !otherObj.item1.input &&
            otherObj.item2.check.length == 0 && !otherObj.item2.input &&
            !otherObj.item3.input1 && !otherObj.item3.input2 && !otherObj.item3.input3 && !otherObj.item3.input4 &&
            otherObj.item4.check.length == 0 && !otherObj.item4.input &&
            !otherObj.item5.input1 && !otherObj.item5.input2 &&
            !otherObj.item6.input
          ) {
            this.$message.error(`请填写【其它安全生产情况情况】`)
            return false
          }
          // 安全生产隐患整改情况 校验
          let hiddenDangerObj = this.hiddenDangerObj
          let notInputDanger = false
          hiddenDangerObj.list.forEach((item, index) => {
            if (!item.input1 && !item.input2 && !item.input3) {
              notInputDanger = true
            }
          })
          if (notInputDanger && !hiddenDangerObj.other) {
            this.$message.error(`请填写【安全生产隐患整改情况】`)
            return false
          }
          return true
        },
        // 处理增、删、改操作
        async handleSave(status) {
            let formInfo = {
              managerDutyPerf: this.managerDutyPerf,
              subManagerDutyPerf: this.subManagerDutyPerf,
              keyPartOfControl: this.keyPartOfControl,
              others: this.others,
              hiddenDanger: this.hiddenDanger,
            }
            if (status !== 'DELETE' && !this.validateForm()) return
            if (status !== 'DELETE' && !this.validateDetails()) return
            if (this.loading[status]) return
            this.loading[status] = true
            const params = {
                ...this.formInfo,
                ...formInfo,
                auditStatusEnum: status,
                id: this.$route.query.id || void 0,
            }
            const { pageType } = this.$route.query
            const fn = pageType === 'edit' ? updateProductionRecord : addPMProductionRecord
            const map = {
                DELETE: deleteProductionRecord,
                DRAFT: fn,
                SUBMITTED: fn,
            }
            const [err, res] = await map[status](params)
            if (!err) {
                this.$message.success('成功')
                this.handleClose()
            }
            this.loading[status] = false
        },
        handleClose() {
            this.$multiTab.close(this.$route.fullpath)
        },
    },
}
</script>

<style lang="less" scoped>
@deep: ~'>>>';
.page-body {
    .ant-radio-group {
        // width: 100%;
    }
    form .ant-mentions,
    form textarea.ant-input {
        height: auto;
        width: 100%;
    }
    .one-line {
      display: flex;
      align-items: end;
      margin-bottom: 10px;
    }
    .blodfont {
      font-weight: bold;
    }
    @{deep} .under-line {
      position:relative;
    }
    @{deep} .under-line .title{
      position: absolute;
      height: 32px;
      left: 0px;
      // top: 4px;
      z-index: 10;
      background: #fff;
      display: flex;
      align-items: end;
      // padding-right: 10px;
    }
    @{deep} .under-line .ant-input{
      padding: 0 11px;
      min-height: 32px;
      border: none;
      box-shadow: none;
      background: url('~@/assets/under-line.png') repeat;
      background-position-y: -1px;
    }
    @{deep} .under-line textarea.ant-input{
      resize: none;
      min-height: 66px;
      line-height: 32px;
    }
    @{deep} .under-line .ant-input:focus {
      border: none !important;
      box-shadow: none !important;
    }
    @{deep} .under-line .ant-input:hover {
      border: none !important;
      box-shadow: none !important;
    }
}
.row-title {
    font-weight: bold;
    font-size: 16px;
}
.secondary-level-title {
    text-indent: 2em;
    font-size: 14px;
}
.tool-btns {
    display: flex;
    justify-content: flex-end;
    @{deep} .ant-btn + .ant-btn {
        margin-left: 12px;
    }
}
</style>
